package saa.model.disciplina;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

import saa.model.Curso;
import saa.model.periodo.OfertaDisciplina;

@Entity
@NamedQueries({ @NamedQuery(name = "Disciplina.findById", query = "SELECT d FROM Disciplina d WHERE d.id = :id") })
public class Disciplina implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;

	private String nome;
	private int cargaHoraria;
	private String descricao;

	@ManyToOne
	private Curso curso;
	@ManyToOne
	private AreaDisciplina area;
	@ManyToMany(fetch = FetchType.LAZY)
	private Set<CategoriaDisciplina> categorias;

	@ManyToMany(fetch = FetchType.LAZY)
	private Set<Disciplina> preRequisitos;

	@OneToMany(mappedBy = "disciplina")
	private List<OfertaDisciplina> ofertas;

	public Disciplina() {
	}

	public Disciplina(String nome, int cargaHoraria, boolean anual,
			Set<Disciplina> ementasRelacionadas) {
		this.nome = nome;
		this.cargaHoraria = cargaHoraria;
		this.preRequisitos = ementasRelacionadas;
	}

	public Disciplina(String nome, int cargaHoraria) {
		this(nome, cargaHoraria, true, new HashSet<Disciplina>());
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public int getCargaHoraria() {
		return cargaHoraria;
	}

	public void setCargaHoraria(int cargaHoraria) {
		this.cargaHoraria = cargaHoraria;
	}

	public Set<Disciplina> getEmentasRelacionadas() {
		return preRequisitos;
	}

	public void setEmentasRelacionadas(Set<Disciplina> ementasRelacionadas) {
		this.preRequisitos = ementasRelacionadas;
	}

	public void adicionarEmentaRelacionada(Disciplina ementaRelacionada) {
		this.preRequisitos.add(ementaRelacionada);
	}
}